#include "Vector.h"

Vector::Vector()
{
	// default vector
	this->x = 0.0f;
	this->y = 0.0f;
	this->z = 0.0f;

	this->dir = 0.0f;
	this->len = 0.0f;
}

Vector::Vector(float x, float y, float z)
{
	this->x = x;
	this->y = y;
	this->z = z;

	calcDir();
	calcLen();
}
float Vector::getX() { return this->x; }
float Vector::getY() { return this->y; }
float Vector::getZ() { return this->z; }


void Vector::calcLen()
{
	float x, y, z;

	x = pow(this->x, 2);
	y = pow(this->y, 2);
	z = pow(this->z, 2);

	this->len = sqrtf(pow(this->x,2) + pow(this->y,2) + pow(this->z,2));
}
void Vector::calcDir()
{
	// todo
}
void Vector::normalize()
{
	// NORMALIZE
	calcLen();
	
	this->x /= this->len;
	this->y /= this->len;
	this->z /= this->len;
}

std::string Vector::toString()
{
	char str[512];
	
	sprintf_s(str, "{ %.2f, %.2f, %.2f }", this->x, this->y, this->z);
		
	std::string toReturn;
	
	toReturn = str;

	return toReturn;

}


/*
	OVERLOADED OPERATORS
*/

Vector Vector::operator+(Vector v2)
{
	Vector toReturn;

	toReturn.x = this->x + v2.x;
	toReturn.y = this->y + v2.y;
	toReturn.z = this->z + v2.z;

	return toReturn;
}
Vector Vector::operator-(Vector v2)
{
	Vector toReturn;

	toReturn.x = this->x - v2.x;
	toReturn.y = this->y - v2.y;
	toReturn.z = this->z - v2.z;

	return toReturn;
}

Vector Vector::operator*(Vector v2)
{
	Vector toReturn;

	toReturn.x = this->x * v2.x;
	toReturn.y = this->y * v2.y;
	toReturn.z = this->z * v2.z;

	return toReturn;
}

Vector Vector::operator/(Vector v2)
{
	Vector toReturn;

	toReturn.x = this->x / v2.x;
	toReturn.y = this->y / v2.y;
	toReturn.z = this->z / v2.z;

	return toReturn;
}
void Vector::operator+=(Vector v2)
{
	this->x += v2.x;
	this->y += v2.y;
	this->z += v2.z;
}
void Vector::operator-=(Vector v2)
{
	this->x -= v2.x;
	this->y -= v2.y;
	this->z -= v2.z;
}
void Vector::operator*=(Vector v2)
{
	this->x *= v2.x;
	this->y *= v2.y;
	this->z *= v2.z;
}
void Vector::operator/=(Vector v2)
{
	this->x /= v2.x;
	this->y /= v2.y;
	this->z /= v2.z;
}
Vector Vector::operator+(int i2)
{
	Vector toReturn;

	toReturn.x += i2;
	toReturn.y += i2;
	toReturn.z += i2;

	return toReturn;
}
Vector Vector::operator-(int i2)
{
	Vector toReturn;

	toReturn.x -= i2;
	toReturn.y -= i2;
	toReturn.z -= i2;

	return toReturn;
}
Vector Vector::operator*(int i2)
{
	Vector toReturn;

	toReturn.x *= i2;
	toReturn.y *= i2;
	toReturn.z *= i2;

	return toReturn;
}
Vector Vector::operator/(int i2)
{
	Vector toReturn;

	toReturn.x /= i2;
	toReturn.y /= i2;
	toReturn.z /= i2;

	return toReturn;
}
void Vector::operator+=(int i2)
{
	this->x += i2;
	this->y += i2;
	this->z += i2;
}
void Vector::operator-=(int i2)
{
	this->x -= i2;
	this->y -= i2;
	this->z -= i2;
}
void Vector::operator*=(int i2)
{
	this->x *= i2;
	this->y *= i2;
	this->z *= i2;
}

void Vector::operator/=(int i2)
{
	this->x /= i2;
	this->y /= i2;
	this->z /= i2;
}

